home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / standards / sgml / nist / parse1 / dtdgrps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-13  |  10.8 KB  |  387 lines

  1. /* National Institute of Standards and Technology (NIST)
  2. /* National Computer System Laboratory (NCSL)
  3. /* Office Systems Engineering (OSE) Group
  4. /* ********************************************************************
  5. /*                            D I S C L A I M E R
  6. /*                              (March 8, 1989)
  7. /*  
  8. /* There is no warranty for the NIST NCSL OSE SGML parser and/or the NIST
  9. /* NCSL OSE SGML parser validation suite.  If the SGML parser and/or
  10. /* validation suite is modified by someone else and passed on, NIST wants
  11. /* the parser's recipients to know that what they have is not what NIST
  12. /* distributed, so that any problems introduced by others will not
  13. /* reflect on our reputation.
  14. /* 
  15. /* Policies
  16. /* 
  17. /* 1. Anyone may copy and distribute verbatim copies of the SGML source
  18. /* code as received in any medium.
  19. /* 
  20. /* 2. Anyone may modify your copy or copies of SGML parser source code or
  21. /* any portion of it, and copy and distribute such modifications provided
  22. /* that all modifications are clearly associated with the entity that
  23. /* performs the modifications.
  24. /* 
  25. /* NO WARRANTY
  26. /* ===========
  27. /* 
  28. /* NIST PROVIDES ABSOLUTELY NO WARRANTY.  THE SGML PARSER AND VALIDATION
  29. /* SUITE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
  30. /* EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  32. /* THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS
  33. /* WITH YOU.  SHOULD THE SGML PARSER OR VALIDATION SUITE PROVE DEFECTIVE,
  34. /* YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  35. /* 
  36. /* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL NIST BE LIABLE FOR
  37. /* DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,
  38. /* INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  39. /* INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
  40. /* BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
  41. /* FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY
  42. /* NIST) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF
  43. /* SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  44. */
  45.  
  46. /************************************************************************/
  47. /*   TITLE:          SGML PARSER                                        */
  48. /*   SYSTEM:         DTD PROCESSOR                                      */
  49. /*   SUBSYSTEM:                                                         */
  50. /*   SOURCE FILE:    DTDGRPS.C                                          */
  51. /*   AUTHOR:         Jim Heath                                          */
  52. /*                                                                      */
  53. /*   DATE CREATED:                                                      */
  54. /*   LAST MODIFIED:                                                     */
  55. /*                                                                      */
  56. /*                  REVISIONS                                           */
  57. /*   WHEN      WHO            WHY                                       */
  58. /************************************************************************/
  59. #include <stdio.h>
  60. #include <setjmp.h>
  61. #include "qntyset.h"
  62. #include "dtd.h"
  63. #include "dtdfncs.h"
  64. #include "dtdglbl.h"
  65.  
  66. typedef enum {
  67.    sawGRPO, sawGRPC, inNAME, endofNAME, sawOI, sawCONNECTOR, sawEE, endGRP}
  68. STATES;
  69. STATES state = sawGRPO;
  70. static char cm[1024];
  71. static char *cmptr = cm;
  72. int nestlvl, namelength;
  73.  
  74. /* ============================================================ */
  75. #define NAMEGROUP 0
  76. #define CONTENTMODEL 1
  77.  
  78. char *getagroup( flag)
  79. int flag;    /* 0 => namegroup, 1 => contentmodel */
  80. {
  81.    register int count = 0, c;
  82.  
  83.    FUNCTRACE("getagroup");
  84.    cmptr = cm;
  85.    nestlvl = 0;
  86.    memset(cm, '\0', sizeof(cm));
  87.  
  88.    state = sawGRPO;
  89.    for (count = 0; ;count++) {
  90.       if (count != 0)
  91.          if (nestlvl == 0)
  92.             break;
  93.       switch(state) {
  94.       case sawGRPO:
  95.          state = (STATES) dosawGRPO();
  96.          break;
  97.       case sawGRPC:
  98.          state = (STATES) dosawGRPC();
  99.          break;
  100.       case endGRP:
  101.          state = (STATES) doendGRP();
  102.          break;
  103.       case inNAME:
  104.          state = (STATES) doinNAME();
  105.          break;
  106.       case sawOI:
  107.          if (flag == NAMEGROUP)
  108.             syntxerr("illegal character in name token group");
  109.          state = (STATES) dosawOI();
  110.          break;
  111.       case sawCONNECTOR:
  112.          state = (STATES) dosawCONNECTOR();
  113.          break;
  114.       case endofNAME:
  115.          state = (STATES) doendofNAME();
  116.          break;
  117.       case sawEE:
  118.          state = (STATES) dosawEE();
  119.          break;
  120.       default:
  121.          terminate(1, "illegal state in getagroup");
  122.       }
  123.    }
  124.    if ((c = TOUPPER(jgetc())) == EOF)
  125.       terminate(1, "EOF in element declaration");
  126.    if (isoi(c)) {
  127.       ADDCHAR(c);
  128.       *cmptr++ = c;
  129.    }
  130.    else
  131.       jungetc(c);
  132.    return(cm);
  133. }
  134. /* ============================================================ */
  135. int dosawGRPO()
  136. {
  137.    register int c;
  138.    INPTS();
  139.    if ((c = TOUPPER(jgetc())) == EOF)
  140.       terminate(1,"EOF in declaration");
  141.    if (issepchar(c))
  142.       return(sawGRPO);
  143.    ADDCHAR(c);
  144.    *cmptr++ = c;
  145.    if (c == GRPO){
  146.       nestlvl++;
  147.       return(sawGRPO);
  148.    }
  149.    if (c == RNI || (isnmchar(c))) {
  150.       namelength = 1;
  151.       return(inNAME);
  152.    }
  153.    syntxerr("syntxerr in group model");
  154. }
  155. /* ============================================================ */
  156. int dosawGRPC()
  157. {
  158.    register int c;
  159.    INPTS();
  160.    if ((c = TOUPPER(jgetc())) == EOF)
  161.       terminate(1,"EOF in declaration");
  162.    c &= 0xFF;
  163.    if (issepchar(c))
  164.       return(endGRP);
  165.    ADDCHAR(c);
  166.    *cmptr++ = c;
  167.    if (c == GRPC){
  168.       nestlvl--;
  169.       return(sawGRPC);
  170.    }
  171.    if (isoi(c))
  172.       return(sawOI);
  173.    if (isconnector(c))
  174.       return(sawCONNECTOR);
  175.    if ((char) c == EE)
  176.       return(sawEE);
  177.    syntxerr("syntxerr in group");
  178. }
  179. /* ============================================================ */
  180. int doendGRP()
  181. {
  182.    register int c;
  183.    INPTS();
  184.    if ((c = TOUPPER(jgetc())) == EOF)
  185.       terminate(1,"EOF in declaration");
  186.    c &= 0xFF;
  187.    if (issepchar(c))
  188.       return(endGRP);
  189.    ADDCHAR(c);
  190.    *cmptr++ = c;
  191.    if (c == GRPC){
  192.       nestlvl--;
  193.       return(sawGRPC);
  194.    }
  195.    if (isconnector(c))
  196.       return(sawCONNECTOR);
  197.    if ((char) c == EE)
  198.       return(sawEE);
  199.    syntxerr("syntxerr in group");
  200. }
  201. /* ============================================================ */
  202. int doinNAME()
  203. {
  204.    register int c;
  205.    if ((c = TOUPPER(jgetc())) == EOF)
  206.       terminate(1,"EOF in declaration");
  207.    c &= 0xFF;
  208.    if (issepchar(c))
  209.       return(endofNAME);
  210.    ADDCHAR(c);
  211.    *cmptr++ = c;
  212.    if (c == GRPC){
  213.       nestlvl--;
  214.       return(sawGRPC);
  215.    }
  216.    if (isoi(c))
  217.       return(sawOI);
  218.    if (isconnector(c))
  219.       return(sawCONNECTOR);
  220.    if (issepchar(c))
  221.       return(endofNAME);
  222.    if (isnmchar(c)) {
  223.       if (++namelength > NAMELEN)
  224.          syntxerr("name too long in group");
  225.       return(inNAME);
  226.    }
  227.    if ((char) c == EE)
  228.       return(sawEE);
  229.    syntxerr("syntxerr in group");
  230. }
  231. /* ============================================================ */
  232. dosawOI()
  233. {
  234.    register int c;
  235.    INPTS();
  236.    if ((c = TOUPPER(jgetc())) == EOF)
  237.       terminate(1,"EOF in declaration");
  238.    c &= 0xFF;
  239.    if (issepchar(c))
  240.       return(sawOI);
  241.    ADDCHAR(c);
  242.    *cmptr++ = c;
  243.    if (c == GRPC){
  244.       nestlvl--;
  245.       return(sawGRPC);
  246.    }
  247.    if (isconnector(c))
  248.       return(sawCONNECTOR);
  249.    printf("unexpected character = %04x\n", c);
  250.    syntxerr("syntx error in group");
  251. }
  252.  
  253. /* ============================================================ */
  254. dosawCONNECTOR()
  255. {
  256.    register int c;
  257.    INPTS();
  258.    if ((c = TOUPPER(jgetc())) == EOF)
  259.       terminate(1,"EOF in declaration");
  260.    c &= 0xFF;
  261.    if (issepchar(c))
  262.       return(sawCONNECTOR);
  263.    ADDCHAR(c);
  264.    *cmptr++ = c;
  265.    if (c == GRPO){
  266.       nestlvl++;
  267.       return(sawGRPO);
  268.    }
  269.    if (c == RNI || (isnmchar(c))) {
  270.       namelength = 1;
  271.       return(inNAME);
  272.    }
  273.    syntxerr("syntxerr in group");
  274. }
  275. /* ============================================================ */
  276. doendofNAME()
  277. {
  278.    register int c;
  279.    INPTS();
  280.    if ((c = TOUPPER(jgetc())) == EOF)
  281.       terminate(1,"EOF in declaration");
  282.    c &= 0xFF;
  283.    if (issepchar(c))
  284.       return(endofNAME);
  285.    ADDCHAR(c);
  286.    *cmptr++ = c;
  287.    if (c == GRPC){
  288.       nestlvl--;
  289.       return(sawGRPC);
  290.    }
  291.    if (isconnector(c))
  292.       return(sawCONNECTOR);
  293.    syntxerr("syntxerr in group");
  294. }
  295. /* ============================================================ */
  296. dosawEE()
  297. {
  298.    register int c;
  299.    INPTS();
  300.    if ((c = TOUPPER(jgetc())) == EOF)
  301.       terminate(1,"EOF in declaration");
  302.    c &= 0xFF;
  303.    if (issepchar(c))
  304.       return(sawEE);
  305.    ADDCHAR(c);
  306.    *cmptr++ = c;
  307.    if (c == GRPC){
  308.       nestlvl--;
  309.       return(sawGRPC);
  310.    }
  311.    if (isconnector(c))
  312.       return(sawCONNECTOR);
  313.    syntxerr("syntxerr in group");
  314. }
  315. /* ============================================================ */
  316. INPTS()
  317. {
  318.    char namearray[NAMELEN + 1], *nameptr = namearray;
  319.    char *resptr;
  320.    register int c, synkey;
  321.    do {
  322.       if ((c = jgetc()) == EOF)
  323.          return(EOF);
  324.    }   while (issepchar(c));
  325.    c &= 0xFF;
  326.    if (c != PERO) {
  327.       jungetc(c);
  328.       return;
  329.    }
  330.    /* input the parameter entity name */
  331.    if (INPNAME(&nameptr, NAMELEN - 1, noxlat) < GOOD)
  332.       syntxerr("syntxerr while processing group");
  333.    nameptr = namearray;
  334.    synkey = search(PARM_ENT_NAME, nameptr, &resptr);
  335.    if (synkey != NULL)
  336.       syntxerr("syntxerr while processing group");
  337.    if((c = jgetc()) == EOF)
  338.       terminate(1, "End of File found while resolving parameter entity reference");
  339.    if(c != REFC)
  340.       jungetc(c);
  341.    /* unget parameter literal */
  342.    ckts(resptr);
  343.    ungetreslv(resptr);
  344.    /* indicate we are within an entity */
  345.    SETFLAG(IN_ENTITY);
  346. }
  347. /* ============================================================ */
  348. void ckts(ptr)
  349. char *ptr;
  350. {
  351.    register char *tptr;
  352.    register int nestlvl = 0;
  353.  
  354.    /* first scan through cking that GRPO's balance GRPC's */
  355.    for (tptr = ptr, nestlvl = 0; *tptr != '\0'; tptr++) {
  356.       if (*tptr == GRPO)
  357.          nestlvl++;
  358.       else if (*tptr == GRPC)
  359.          nestlvl--;
  360.       if (nestlvl < 0)
  361.          syntxerr("unbalanced GRPO's/GRPC's parameter entity reference");
  362.    }
  363.    if (nestlvl != 0)
  364.       syntxerr("syntxerr in parameter entity");
  365. }
  366. /* ============================================================ */
  367. int issepchar(c)
  368. char c;
  369. {
  370.    switch (c) {
  371.    case ' ':
  372.    case CR:
  373.    case LF:
  374.    case TAB:
  375.       return(TRUE);
  376.    }
  377.    return(FALSE);
  378. }
  379. /* ============================================================ */
  380. /* ============================================================ */
  381. /* ============================================================ */
  382. /* ============================================================ */
  383. /* ============================================================ */
  384. /* ============================================================ */
  385. /* ============================================================ */
  386. /* ============================================================ */
  387.